package com.zzz.framework.config.http;

import com.zzz.framework.exception.BizException;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class LoadBalance {
    /**
     * 系统别名转域名
     */
    private Map<String, String[]> systemAliasMap = new HashMap() {{
        put("sales.oms.detail.ui", new String[]{"http://oms.zhaogangrenuat.com"});
        put("sso.ui", new String[]{"http://passport.zhaogangrentest.com"});
    }};

    public String getDomainBySystemAlias(String systemAlias) {
        String[] domains = systemAliasMap.get(systemAlias);
        if (domains == null) {
            throw new BizException("未配置负载均衡");
        }
        return domains[RandomUtils.nextInt(0, domains.length - 1)];//随机负载均衡
    }
}
